package com.lagou.jedisclaster.config;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class Cluster {
    private static JedisCluster jedisCluster;

    static {
        Set<HostAndPort> hostAndPortSet = new HashSet<>();
        hostAndPortSet.add(new HostAndPort("192.168.80.121", 8001));
        hostAndPortSet.add(new HostAndPort("192.168.80.121", 8002));
        hostAndPortSet.add(new HostAndPort("192.168.80.122", 8001));
        hostAndPortSet.add(new HostAndPort("192.168.80.122", 8002));
        hostAndPortSet.add(new HostAndPort("192.168.80.123", 8001));
        hostAndPortSet.add(new HostAndPort("192.168.80.123", 8002));

        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(100);
        jedisPoolConfig.setMaxTotal(500);
        jedisPoolConfig.setMinIdle(0);
        jedisPoolConfig.setMaxWaitMillis(3000);
        jedisPoolConfig.setTestOnBorrow(true);
        jedisCluster = new JedisCluster(hostAndPortSet, jedisPoolConfig);
    }

    public static JedisCluster getJedisCluster () {
        return jedisCluster;
    }
}
